home *** CD-ROM | disk | FTP | other *** search
- /*
- IC CheckBox What.c
-
- Custom code to handle a checkbox.
-
- IC CheckBoxes work as follows (since I am creating them, I can define
- how they work ;-)
-
- True/False for a pref is determined by the existance
- of the pref resource; if the resource exists, the
- box is checked; if the resource doesn't exist, the
- box is unchecked.
-
- This means that the resource associated with the
- checkbox is very volatile and should not contain any
- valuable information because it could be destroyed
- (and lost) if someone unchecks and saves the changes.
-
- */
-
- #include "IC Types.h"
- #include "IC API.h"
-
- #include "IC Window Globals.h"
- #include "IC Subs.h"
- #include "IC Dialogs.h"
- #include "IC Windows.h"
- #include "IC CheckBox What.h"
- #include "IC Document.h"
-
- /*
- WhatOpenCheckBox
-
- Called when a checkbox item is opened. The control
- is already created, we just need to set the initial
- setting.
- */
- OSErr WhatOpenCheckBox(WindowType wt,short item){
- OSErr err=noErr;
- long attr;
- short set=0;
- Handle hand=NewHandle(0);
- ICInstance inst=GetInstance();
- StringPtr keyp=WindowInfo[wt].items[item]->key;
-
- err=ICMapErr(ICFindPrefHandle(inst,keyp,&attr,hand));
-
- if (err==noErr){
- // then the pref exists; initial setting should be true
- set=1;
- }
-
- DisposeHandle(hand);
-
- // we know what the setting of the control should be,
- // set it up now.
-
- SetDCtlValue(WindowInfo[wt].window,item,set);
-
- return noErr;
- }
-
- /*
- WhatClickCheckBox
-
- Called when a checkbox item has been clicked. Toggle
- the display in the window.
- */
- OSErr WhatClickCheckBox(WindowType wt,short item,EventRecord* er){
- short val=GetDCtlValue(WindowInfo[wt].window,item);
-
- if (val!=0)
- val=0;
- else
- val=1;
-
- SetDCtlValue(WindowInfo[wt].window,item,val);
-
- return noErr;
- }
-
- /*
- WhatFlushCheckBox
-
- Save the setting to the pref file.
- */
- OSErr WhatFlushCheckBox(WindowType wt,short item){
- short val=GetDCtlValue(WindowInfo[wt].window,item);
- Handle h;
- OSErr err=noErr,junk;
- ICInstance inst=GetInstance();
- ICAttr attr;
- Boolean wasSet=false;
- StringPtr keyp=WindowInfo[wt].items[item]->key;
-
- h=NewHandle(0);
- junk=ICMapErr(ICFindPrefHandle(inst,keyp,&attr,h));
- if (junk==noErr)
- wasSet=true;
- DisposeHandle(h);
-
- if ((val==0)&&(wasSet)){
- // need to delete the pref; it exists
- ICDeletePref(GetInstance(),WindowInfo[wt].items[item]->key);
- DirtyDocument();
- } else if ((val==1)&&(!wasSet)){
- // need to ensure pref exists
- h=NewHandle(2); // create a new handle to two bytes
- if (h!=(Handle)0){
- ICSetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,
- (ICAttr)0,h);
- DisposeHandle(h);
- DirtyDocument();
- } else
- err=MemError();
- }
- return err;
- }
-